/**
 * 封装ajax
 */
const sendAjax = function (url) {
  return new Promise((resolve, reject) => {
    const xhr = new XMLHttpRequest()
    xhr.responseType = 'json'
    xhr.open('GET', url)
    xhr.send()
    xhr.onreadystatechange = function () {
      if (xhr.readyState === 4) {
        if (xhr.status >= 200 && xhr.status < 300) {
          resolve(xhr.response)
        } else {
          reject(xhr.status)
        }
      }
    }
  })
}

const test = function (){
  sendAjax('https://api.apiopen.top/getJoke').then((data) => {
    console.log(data);
  }).catch((reason) => {
    console.log(reason);
  })
}